package com.devmindset.jpatoolbox.manytomany;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.devmindset.jpatoolbox.ReadOnlyModelList;
import com.devmindset.jpatoolbox.base.BaseEntity;


/**
 * Entity on the forward side used in M-to-M wiring tests. 
 *
 * @author <a href="mailto:ice.penov@devmindset.com">Ice Penov</a>
 */
@Entity(name = "FORWARD_MM")
@Table(name = "FORWARD_MM")
public class Forward extends BaseEntity {
  
  @ManyToMany(cascade = CascadeType.ALL)
  @JoinTable(name = "FORWARDM_INVERSEM")
  private List<Inverse> inverses = new ArrayList<Inverse>();

  @SuppressWarnings("unchecked")
  public List<Inverse> getInverses() {
    return ReadOnlyModelList.decorate(this.inverses);
  }
  
  /**
   * Sets the given list of inverses.
   * 
   * @param inverses the list
   */
  public void setInverses(List<Inverse> inverses) {
    com.devmindset.jpatoolbox.ManyToManyUtil.wireCollection(this, inverses, Forward.class, Inverse.class);
  }

  /**
   * Adds an inverse to this forward.
   * 
   * @param inverse the inverse to be added
   */
  public void addInverse(Inverse inverse) {
    com.devmindset.jpatoolbox.ManyToManyUtil.wireAddition(this, inverse, Forward.class, Inverse.class);
  }
  
  /**
   * Removes the given inverse from this forward
   * @param inverse to be removed
   */
  public void removeInverse(Inverse inverse) {
    com.devmindset.jpatoolbox.ManyToManyUtil.wireRemoval(this, inverse, Forward.class, Inverse.class);
  }    

}
